/*
 * Copyright (C) 2013 The i18nCTS Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.i18nCTS.view;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

import com.googlecode.i18nCTS.provider.i18nCTSProvider;

public abstract class AbstractSectionFragment extends Fragment {
	Context mContext = null;
	static int flags = 0;

	public abstract void buildList(i18nCTSProvider provider);
	public abstract String getCategory();
	
	public void setContext(Context context) {
		mContext = context;
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// assign current context
		mContext = getActivity();		

		// fill the data
		i18nCTSProvider provider = new i18nCTSProvider(mContext);
		buildList(provider);
		provider.commit();
		
		// import the expected data from XML
		provider.importXMLFile(getCategory());
		
		// if (needed) export the test result
		provider.exportXMLFile(getCategory());

		// display the context in the app client area as HTML
		WebView webView = new WebView(mContext);
		webView.loadData(provider.getHTML(), "text/html; charset=UTF-8", null);
		
		return webView;
	}
}
